<?php
/*
 * Copyright 2009 Eat Local Food, LLC
 * Copyright (c) 2007 osCommerce (this file was written after
 * code review of osCommerce).
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */


function country_list()
{
	$values[0]['value'] = '0';
	$values[0]['title'] = 'No Selection';
	$sqlQuery = 'select countries_id, countries_name from ' . TABLE_COUNTRIES . ' order by countries_name ';
	$dataReturned = mysql_query($sqlQuery) or die(mysql_error());
	$i = 1;
	while($row = mysql_fetch_array($dataReturned))
	{
		$values[$i]['value'] = $row['countries_id'];
		$values[$i]['title'] = $row['countries_name'];
		$i++;
	}
	return $values;
}

function order_status_list()
{
	//Get value from database in case its been modified during this roundtrip.
	$sqlQuery = 'select configuration_key, configuration_value from ' . TABLE_CONFIGURATION . ' ' .
	'where configuration_key = \'DEFAULT_LANGUAGE\'';
	$dataReturned = mysql_query($sqlQuery) or die(mysql_error());
	while($row = mysql_fetch_array($dataReturned))
	{
		$language_code = $row['configuration_value'];
	}

	$sqlQuery = 'select languages_id from ' . TABLE_LANGUAGES . ' where code=\'' . $language_code . '\'';
	$dataReturned = mysql_query($sqlQuery) or die(mysql_error());
	while($row = mysql_fetch_array($dataReturned))
	{
		$language_id = (int)$row['languages_id'];
		break;	}

	$sqlQuery = 'select orders_status_id, orders_status_name from ' . TABLE_ORDERS_STATUS . ' ' . 
	'where language_id = ' . $language_id . ' order by orders_status_id ';
	$dataReturned = mysql_query($sqlQuery) or die(mysql_error());
	$i = 0;
	while($row = mysql_fetch_array($dataReturned))
	{
		$values[$i]['value'] = $row['orders_status_id'];
		$values[$i]['title'] = $row['orders_status_name'];
		$i++;
	}
	return $values;
}

function tax_class_list()
{
	$values[0]['value'] = '0';
	$values[0]['title'] = 'No Selection';
	$sqlQuery = 'select tax_class_id, tax_class_title, tax_class_description from ' . TABLE_TAX_CLASS . ' order by tax_class_title ';
	$dataReturned = mysql_query($sqlQuery) or die(mysql_error());
	$i = 1;
	while($row = mysql_fetch_array($dataReturned))
	{
		$values[$i]['value'] = $row['tax_class_id'];
		$values[$i]['title'] = $row['tax_class_title'] . ' (' . $row['tax_class_description'] . ')';
		$i++;
	}
	return $values;
}

function geo_zone_list()
{
	$values[0]['value'] = '0';
	$values[0]['title'] = 'No Selection';
	$sqlQuery = 'select geo_zone_id, geo_zone_name, geo_zone_description  from ' . TABLE_GEO_ZONES . ' order by geo_zone_name ';
	$dataReturned = mysql_query($sqlQuery) or die(mysql_error());
	$i = 1;
	while($row = mysql_fetch_array($dataReturned))
	{
		$values[$i]['value'] = $row['geo_zone_id'];
		$values[$i]['title'] = $row['geo_zone_name'] . ' (' . $row['geo_zone_description'] . ')';
		$i++;
	}
	return $values;
}

function zone_list()
{
	//Get value from database in case its been modified during this roundtrip.
	$sqlQuery = 'select configuration_key, configuration_value from ' . TABLE_CONFIGURATION . ' ' .
	'where configuration_key = \'STORE_COUNTRY\'';
	$dataReturned = mysql_query($sqlQuery) or die(mysql_error());
	while($row = mysql_fetch_array($dataReturned))
	{
		$store_country = $row['configuration_value'];
	}

	$values[0]['value'] = '0';
	$values[0]['title'] = 'No Selection';
	$sqlQuery = 'select zone_id, zone_name  from ' . TABLE_ZONES . ' ' .
	'where zone_country_id = '. $store_country . ' order by zone_name ';
	$dataReturned = mysql_query($sqlQuery) or die(mysql_error());
	$i = 1;
	while($row = mysql_fetch_array($dataReturned))
	{
		$values[$i]['value'] = $row['zone_id'];
		$values[$i]['title'] = $row['zone_name'];
		$i++;
	}
	return $values;
}

function product_list(&$value, $handle, $languageId)
{
	$sqlQuery = 'select pd.products_id, pd.products_name, p.products_image ' .
	'from  ' . TABLE_PRODUCTS_DESCRIPTION . ' pd, ' . TABLE_PRODUCTS . ' p ' . 
	'where p.products_id=pd.products_id and pd.language_id='. $languageId . ' ' .
	'group by pd.products_id order by pd.products_name';
	$dataReturned = mysql_query($sqlQuery) or die(mysql_error());
	$i=0;
	while($row = mysql_fetch_array($dataReturned))
	{
		$value{$handle . 'MetaData'}{'products'}{$i}{'id'}=(int)$row['products_id'];
		$value{$handle . 'MetaData'}{'products'}{$i}{'name'}=$row['products_name'];
		$value{$handle . 'MetaData'}{'products'}{$i}{'image'}=$row['products_image'];
		$image_size = @getimagesize(DIR_FS_CATALOG_IMAGES . 'products/' . $row['products_image']);
		$value{$handle . 'MetaData'}{'products'}{$i}{'image_width'}= $image_size[0];
		$value{$handle . 'MetaData'}{'products'}{$i}{'image_height'}= $image_size[1];
		$i++;
	}
}
?>
